package high.concurrent.controller;


import high.concurrent.request.LockCouponRecordRequest;
import high.concurrent.service.CouponRecordService;
import high.concurrent.utils.JsonData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 黄保泽
 * @since 2021-07-17
 */
@RestController
@RequestMapping("/api/coupon_record/v1/")
@Api(tags = "优惠券领取模块")
public class CouponRecordController {


    @Autowired
    private CouponRecordService couponRecordService;


    /**
     * 查询个人领券信息
     * @param page   当前页码
     * @param size   每页记录数
     * @return
     */
    @ApiOperation(value = "查询个人领券信息")
    @GetMapping("selectPersonCouponRecord")
    public JsonData selectPersonCouponRecord(@ApiParam(value = "当前页码") @RequestParam(value = "page", defaultValue = "1") Integer page,
                                             @ApiParam(value = "每页记录数") @RequestParam(value = "size", defaultValue = "10") Integer size){

        JsonData jsonData = couponRecordService.selectPersonCouponRecord(page, size);
        return jsonData;
    }


    /**
     * 领券信息详情
     * @param couponRrecordId   领券表主键id
     * @return
     */
    @ApiOperation(value = "领券信息详情")
    @GetMapping("getCouponRecordDetail")
    public JsonData getCouponRecordDetail(@ApiParam(value = "领券表主键id", required = true) @RequestParam(value = "coupon_record_id") Long couponRrecordId){

        JsonData jsonData = couponRecordService.getCouponRecordDetail(couponRrecordId);
        return jsonData;
    }


    /**
     * 下单锁定优惠券
     * @param lockCouponRecordRequest
     * @return
     */
    @ApiOperation(value = "下单锁定优惠券")
    @PostMapping("lockCouponRecord")
    public JsonData lockCouponRecord(@ApiParam(value = "优惠券锁定信息") @RequestBody LockCouponRecordRequest lockCouponRecordRequest){

        JsonData jsonData = couponRecordService.lockCouponRecord(lockCouponRecordRequest);
        return jsonData;
    }

    /**
     * 测试死信队列
     * @return
     */
    @ApiOperation(value = "测试死信队列")
    @PostMapping("dealQueueTest")
    public void dealQueueTest(){

        couponRecordService.dealQueueTest();
    }
}

